<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
	<body>
		<h1 class="pagetitle">
			新增/修改采购订单
		</h1>
		
		<script type="text/javascript">
			function addRow(){
				var purchaseOrderSubTable = document.getElementById('firstPurchaseOrderSubForClone').cloneNode(true);
				document.getElementById('purchaseOrderSubTable').appendChild(purchaseOrderSubTable);
			}
			
			function checkInputData(){
				var prices = document.getElementsByName('price');
				var partsIds = document.getElementsByName('id');
				var quantitiys = document.getElementsByName('quantity');
				var purchaseOrderSubUnion = "";
				for(var i = 0;i < partsIds.length;i++){
					if(prices[i].value != "" && quantitiys[i].value != "" && quantitiys[i].value != 0){
						var nodeContent = partsIds[i].value + "#" + quantitiys[i].value + "#" + prices[i].value + ":";
						purchaseOrderSubUnion = purchaseOrderSubUnion + nodeContent;
					}
				}
				if(purchaseOrderSubUnion == ""){
					alert("Nothing submit,please check.");
					return false;
				}
				//alert(purchaseOrderSubUnion);
				document.getElementById("purchaseOrder.purchaseOrderSubUnion").value = purchaseOrderSubUnion;
				return true;
			}
		</script>
		<br>
		<h3>供应商:<s:property value="supplier.name"/></h3>
		<div class="column1-unit">
				<s:form method="post" action="purchaseOrder!confirm.action" onsubmit="return checkInputData()" validate="false" theme="css_xhtml">
					
					<s:hidden id="purchaseOrder.purchaseOrderSubUnion" name="purchaseOrder.purchaseOrderSubUnion"></s:hidden>
					<s:hidden id="purchaseOrder.supplierId" name="purchaseOrder.supplierId" value="%{supplier.id}"></s:hidden>
					<s:if test=" purchaseOrder.id != null"><s:hidden name="purchaseOrder.id"></s:hidden></s:if>
						<table class="bigtable" id="purchaseOrderSubTable">
							<tr>
								<th width="150">
								物料类别
								</th>
								<th>
								物料名称
								</th>
								<th width="100">
								单价
								</th>
								<th width="100">
								数量
								</th>
							</tr>
							<s:iterator value="supplier.partsTypeList" status="pl">
								<tr <s:if test="#pl.even">class="tr-even"</s:if>>
								<td><s:property value="name"/></td>
								<td colspan="3">
									<table class="smalltable">
									<s:iterator value="partsList">
										<tr>
										<td><s:property value="name"/><s:hidden name="id"/></td>
										<td width="100"><s:textfield name="price" size="5" cssClass="validate[custom[number]]"></s:textfield></td>
										<td width="100"><s:textfield name="quantity" size="5" cssClass="validate[custom[integer]]"></s:textfield></td>
										</tr>
									</s:iterator>
									</table>
								</td>
								</tr>
							</s:iterator>
						</table>
						<br>
						<table class="formtable">
							<tr>
								<td width="100">
								备注
								</td>
								<td>
								<s:textarea name="purchaseOrder.remark"></s:textarea>
								</td>
							</tr>
						</table>

						<s:submit cssClass="button" theme="simple"></s:submit>
						<s:reset cssClass="button" theme="simple"></s:reset>
				</s:form>
		</div>

	</body>
</html>